package com.example.testscheduled;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.PostConstruct;
import java.io.File;

@Configuration
@EnableScheduling
public class TestSchedule {

    private static final Logger logger = LoggerFactory.getLogger(TestSchedule.class);

    private static final String path ="F:\\jpg";


    @Scheduled(cron = "0 0 0/1 * * ?")
    @PostConstruct
    @Scheduled(fixedRate=5000)
    public void readFile(){
        logger.info("----------------------------------------------------准备开始遍历目录---------------------------------------------");
        File file = new File(path);
        File[]files = file.listFiles();
        for (File f :files ) {
            logger.info("----------------------------读到的文件名是"+f.getName());
        }
    }

}
